package com.example.shopp_2301.adapter

import android.graphics.Color
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.ExplosiveMoney
import com.example.shopp_2301.R

class TypeAdapter:BaseQuickAdapter<ExplosiveMoney,BaseViewHolder>(R.layout.item_type) {
    //定义变量 ---标识是哪一个被选中了
    var selectType = 4
    override fun convert(holder: BaseViewHolder, item: ExplosiveMoney) {
        holder.setText(R.id.type_info,item.info)
        holder.setText(R.id.type_name,item.name)
        //可以在这里修改文字颜色 背景等等 --修改指定的文字
        if(selectType==item.type.toInt()){//选中的item
            holder.getView<TextView>(R.id.type_info).setTextColor(Color.RED)
            holder.getView<TextView>(R.id.type_name).setTextColor(Color.RED)
            holder.getView<TextView>(R.id.type_info).setBackgroundResource(R.drawable.shape_type)
        }else{//未选中背景
            holder.getView<TextView>(R.id.type_info).setTextColor(Color.BLACK)
            holder.getView<TextView>(R.id.type_name).setTextColor(Color.BLACK)
            holder.getView<TextView>(R.id.type_info).background = null
        }
    }
    fun setType(type:Int){
        selectType = type
        notifyDataSetChanged()//适配器刷新，不然布局不会发生变化
    }
}